package com.ellricky.market.ui.act

import android.content.Intent
import android.view.View
import android.widget.AdapterView
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.http.callback.EListCallback
import com.ellricky.baselib.ui.base.BaseRefreshActivity
import com.ellricky.market.*

abstract class ActBaseActivity : BaseRefreshActivity<Void, BasePresenter<Void>, MarketActEntity>() {

    private var pageType: Int = -1


    override fun initUIView() {
        super.initUIView()
        pageType = getPageType()
    }

    override fun getResponseCallback(): BaseCallback {
        return object : EListCallback<MarketActEntity>(this) {
            override fun onSuccess(data: MutableList<MarketActEntity>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }

            override fun onErrorCode(code: String?, msg: String?) {
                super.onErrorCode(code, msg)
                rvView.onRefreshFailed(refresh)
            }

            override fun onHttpError(code: String?, msg: String?) {
                super.onHttpError(code, msg)
                rvView.onRefreshFailed(refresh)
            }
        }
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<MarketActEntity> {
        adapter = MarketActAdapter(this)
        return adapter
    }


    abstract fun getPageType(): Int

    override fun onClickView(v: View?) {
        super.onClickView(v)
        if (v == mBtnRight) {
            jumpAddClue(this)
            return
        }
    }


    override fun onItemClick(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
        val entity = adapter.get(p2)
        jumpActDetail(this, pageType, entity.id, entity.taskType)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        when (resultCode) {
            RESULT_CODE_ACT_DETAIL -> rvView.loadContent(true)
        }
    }


}
